package com.sx.micowell.framework.model

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import com.example.mvvm.base.data.SingleLiveEvent
import com.example.mvvm.base.vm.BaseViewModel
import com.example.mvvm.until.LogUtils
import com.example.mvvm.until.SPUtils
import com.example.mvvm.until.ToastUtils
import com.miloyu.modelnet.network.ApiResponse
import com.miloyu.modelnet.network.HttpClient
import com.miloyu.modelnet.network.tools.RxUtils
import com.miloyu.modelnet.response.InviteShareVO
import com.sx.micowell.R
import com.sx.micowell.framework.binding.BindingCommand
import com.sx.micowell.framework.binding.impl.IBindingAction
import com.uuzuche.lib_zxing.activity.CodeUtils
import sion.my.netmanger2.NetworkManager.getApplication


/**
 * @Author: YY
 * @Time: 2021/9/10
 * @Describe TODO
 */
class InviteFriendModel: BaseViewModel() {

    var inviteDataEvent: SingleLiveEvent<InviteShareVO> = SingleLiveEvent()

    //保存图片事件
    var savePhotoEvent: SingleLiveEvent<Void> = SingleLiveEvent()

    var savePhotoOnClickCommand: BindingCommand<Void> = BindingCommand(IBindingAction {
        LogUtils.d("savePhotoOnClickCommand")
        savePhotoEvent.call()
    })

    var sharePhotoEvent: SingleLiveEvent<Void> = SingleLiveEvent();

    var sharePhotoOnClickCommand: BindingCommand<Void> = BindingCommand(IBindingAction {
        sharePhotoEvent.call()
    })

    init {
        inviteFriend()
    }

    private fun inviteFriend() {
        addSubscribe(HttpClient.instance.apiService
            .inviteFriend()
            .compose(RxUtils.compose())
            .subscribeWith(object : ApiResponse<InviteShareVO>() {

                override fun success(data: InviteShareVO?, msg: String?) {
                    inviteDataEvent.value = data!!
                }

                override fun onFail(e: Throwable?, errorMsg: String?) {

                }

            })
        )
    }


}